<h1>Decorate The Tech Center Tree</h1>
<br/>
<?php if(date('j') == 6){ ?>
<style>
#tree{
	min-width:350px;
	height:350px;
	float:left;
}
</style>
<script type="text/javascript"> 
;(function($){
	var element = {};
	var timeout = null;
	$.fn.jshaker = function(sStop){
		element = $(this);
		element.css('position', 'relative');
		element.find('*').each(function(i, el){
			$(el).css('position', 'relative');
		});
		
        var iFunc = function(){ $.fn.jshaker.animate($(element), sStop); };
        setTimeout(iFunc, 50);
	};
	
	$.fn.jshaker.animate = function(el, sStop){
		$.fn.jshaker.shake(el);
        el.find('*').each(function(i, el){
        	$.fn.jshaker.shake(el);
        });        
        var iFunc = function(){ $.fn.jshaker.animate(el); };
		if(!sStop){
	        timeout = setTimeout(iFunc, 50);
		}else{
			clearTimeout(timeout);
			element.find('*').each(function(i, el){
				$(el).css('top', 0);
				$(el).css('left', 0);
			});
		}
	}
	
	$.fn.jshaker.shake = function(el){
        var pos = $(el).position();
        if(Math.random() > 0.5){
            $(el).css('top', pos['top'] + Math.random() * 20 < 10 ? (Math.random() * 20 * (-1)) : Math.random() * 20);
        } else {
            $(el).css('left', pos['left'] + Math.random() * 20 < 10 ? (Math.random() * 20 * (-1)) : Math.random() * 20);
        }
	}
})(jQuery);
</script>
 <script type="text/javascript"> 
	function shakeGo(){
		//jQuery('#main').jshaker(false);
	}
	
	function shakeStop(){
		//jQuery('#main').jshaker(true);
	}
</script> 
<div id="tree">
	<object width="350" height="350">
	<param name="movie" value="holidays/christmas/christmas.swf">
	<embed src="holidays/christmas/christmas.swf" width="350" height="350">
	</embed>
	</object>
</div>
<?php }else{ ?>
<style>
#tree{
	min-width:350px;
	height:350px;
	background-image:url(images/tree.png);
	background-repeat:no-repeat;
	float:left;
}
</style>
	<script>
	function updateLocation(type, x, y){
		x = x + 370;
		jQuery("#"+type).draggable("destroy");
		document.getElementById(type).style.cursor = 'default';
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				document.getElementById('statusText').innerHTML = "Thank You For Decorating!";
		    }
	    }
	    xmlhttp.open("GET","http://192.168.120.9/techcenter/UpdateTree.php?type="+type+"&x="+x+"&y="+y,true);
	    xmlhttp.send();
	}
	</script>
<div id="tree">
	<?php
	$opts = array('ornament1', 'ornament2', 'ornament3', 'ornament4', 'ornament5', 'ornament6', 'ornament7', 'ornament8', 'ornament9', 'ornament10', 'ornament11', 'ornament12', 'ornament13', 'present1', 'present2', 'present3');
	$totalOrnaments = 13;
	$totalPresents = 3;
	
	$totalOrnaments ++;
	$totalPresents ++;
	?>
    <script>
	jQuery(function() {
		<?php
		foreach($opts as $value){
		?>
		jQuery("#<?php echo $value ?>").draggable({
			stop: function(){
				updateLocation(jQuery(this).attr('id'), jQuery(this).position().left, jQuery(this).position().top);
			}
		});
		<?php } ?>
	});
	</script>
    <?php
	
	$sql = "SELECT * FROM `tbChristmas`";
	$q = db::Query($sql);
	$options = array();
	while($row = $q->fetch()){
		$sql = "SELECT * FROM SPRIDEN, GOBTPAC WHERE SPRIDEN_PIDM = GOBTPAC_PIDM AND GOBTPAC_EXTERNAL_USER = :uname AND SPRIDEN_CHANGE_IND is null";
		$q2 = Oracle::Query($sql, array(':uname'=>$row['sUser']));
		$row2 = $q2->fetch();
		
		$options[$row['sType']] = array($row['sX'], $row['sY'], $row2['SPRIDEN_FIRST_NAME']." ".$row2['SPRIDEN_LAST_NAME']);
		?>
        <script>
		jQuery(function() {
			jQuery("#<?php echo $row['sType'] ?>").draggable("destroy");
			jQuery('#<?php echo $row['sType'] ?>').tooltip({
				delay: 0,
				showURL: false
			});
		});	
		</script>
        <?php
		$temp = 0;
		foreach($opts as $key=>$value){
			if($value == $row['sType']){
				$temp = $key;
			}
		}
		unset($opts[$temp]);
		$opts = array_values($opts);
	}
	$selected_one = 'none';
	if(count($opts) != 0){
		$selected_one = $opts[rand(0, count($opts) - 1)];
	}else{
		$selected_one = 'out';
	}
	if($selected_one != 'out'){
		$sql = "SELECT * FROM `tbHolidayLog` WHERE `sUser` = :user";
		$q = db::Query($sql, array(':user'=>$USER['sUname']));
		$row = $q->fetch();
		if($row == ''){
		$sql = "INSERT INTO `tbHolidayLog` VALUES (:user, 1)";
		db::Query($sql, array(':user'=>$USER['sUname']));
		$iCount = 1;
		}else{
			$sql = "UPDATE `tbHolidayLog` SET `iCount` = :count WHERE `sUser` = :user";
			$iCount = $row['iCount'] + 1;
			db::Query($sql, array(':user'=>$USER['sUname'], ':count'=>$iCount));
		}
		$lucky = rand(0, 100);
		$luck = rand(0, 100);
		if($USER['sUname'] == 'kpeterson5'){
			//$luck = $lucky;
		}
		if($luck != $lucky){
			$selected_one = 'none';
		}
	}
	if($selected_one != 'none' && $selected_one != 'out'){
	?>
	<div id="statusText" align="center" style="margin-left:370px;">
    	You have been choosen to decorate the tree!<br/>
        Please drag the item below onto the tree.
    </div>
    <?php
	}else{
		if($selected_one == 'out'){
	?>
    <div id="statusText" align="center" style="margin-left:370px;">
    	Great job decorating<br/>
        the tree! On Monday the<br/>
        presents under the tree<br/>
        will be able to be opened!<br/>
        <br/>
        Stats:<br/>
        <?php
		$sql = "SELECT * FROM `tbHolidayLog` ORDER BY `iCount` DESC";
		$q = db::Query($sql);
		while($row = $q->fetch()){
			$sql = "SELECT * FROM SPRIDEN, GOBTPAC WHERE SPRIDEN_PIDM = GOBTPAC_PIDM AND GOBTPAC_EXTERNAL_USER = :uname AND SPRIDEN_CHANGE_IND is null";
			$q2 = Oracle::Query($sql, array(':uname'=>$row['sUser']));
			$row2 = $q2->fetch();	
			$sql = "SELECT * FROM `tbChristmas` WHERE `sUser` = :user";
			$q2 = db::Query($sql, array(':user'=>$row['sUser']));
			$c = 0;
			while($row3 = $q2->fetch()){
				$c ++;
			}
			echo $row2['SPRIDEN_FIRST_NAME']." ".$row2['SPRIDEN_LAST_NAME']." - ".$row['iCount']." Attempts - ".$c." Wins<br/>";
		}
		?>
    </div>
    <?php
		}else{
	?>
    <div id="statusText" align="center" style="margin-left:370px;">
    	We are sorry, but you were not chosen to decorate the tree!<br/>
        Try again soon! You have a 1 in 100th chance!<br/>
        <br/>
        <input type="button" value=" Try Again " onclick="location.reload(true)" /><br/>
        <br/>
        Stats:<br/>
        <?php
		$sql = "SELECT * FROM `tbHolidayLog` ORDER BY `iCount` DESC";
		$q = db::Query($sql);
		while($row = $q->fetch()){
			$sql = "SELECT * FROM SPRIDEN, GOBTPAC WHERE SPRIDEN_PIDM = GOBTPAC_PIDM AND GOBTPAC_EXTERNAL_USER = :uname AND SPRIDEN_CHANGE_IND is null";
			$q2 = Oracle::Query($sql, array(':uname'=>$row['sUser']));
			$row2 = $q2->fetch();	
			$sql = "SELECT * FROM `tbChristmas` WHERE `sUser` = :user";
			$q2 = db::Query($sql, array(':user'=>$row['sUser']));
			$c = 0;
			while($row3 = $q2->fetch()){
				$c ++;
			}
			echo $row2['SPRIDEN_FIRST_NAME']." ".$row2['SPRIDEN_LAST_NAME']." - ".$row['iCount']." Attempts - ".$c." Wins<br/>";
		}
		?>
        <br/>
        <br/>
        Days Left Till Break:<br/><br/>
        <span style="font-size:40px;">
		<?php $cdate = mktime(0, 0, 0, 12, 18, 2010, 0);
		$today = time();
		$difference = $cdate - $today;
		if ($difference < 0) { $difference = 0; }
        echo floor($difference/60/60/24);
		?>
		</span>
    </div>
    <?php
		}
	}
	?>
    <?php $count = 1; ?>
    <?php while($count < $totalOrnaments){ ?>
	<?php if(isset($options['ornament'.$count][0])){ ?>
	<div id="ornament<?php echo $count ?>" title="Added By <?php echo $options['ornament'.$count][2] ?>" style="background-image:url(images/ornament<?php echo $count ?>.png); width:27px; height:30px; position:absolute; left:<?php echo $options['ornament'.$count][0] ?>px; top:<?php echo $options['ornament'.$count][1] ?>px"></div>
    <?php }else{ ?>
    	<?php if($selected_one == 'ornament'.$count){ ?>
		<div id="ornament<?php echo $count ?>" style="background-image:url(images/ornament<?php echo $count ?>.png); cursor:move; width:27px; height:30px; margin-left:370px"></div>
    	<?php } ?>
    <?php } ?>
    <?php $count ++; ?>
    <?php } ?>
    
    <?php $count = 1; ?>
    <?php while($count < $totalPresents){ ?>
    <?php if(isset($options['present'.$count][0])){ ?>
	<div id="present<?php echo $count ?>" title="Added By <?php echo $options['present'.$count][2] ?>" style="background-image:url(images/present<?php echo $count ?>.png); width:50px; height:59px; position:absolute; left:<?php echo $options['present'.$count][0] ?>px; top:<?php echo $options['present'.$count][1] ?>px"></div>
    <?php }else{ ?>
    	<?php if($selected_one == 'present'.$count){ ?>
		<div id="present<?php echo $count ?>" style="background-image:url(images/present<?php echo $count ?>.png); cursor:move; width:50px; height:59px; margin-left:370px"></div>
        <?php } ?>
    <?php } ?>
    <?php $count ++; ?>
    <?php } ?>
</div>
<?php } ?>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/>
<?php if(date('j') == 1){ ?>
<h1>Happy Holidays! - Red Box Rental on Me</h1>
<br/>
<center>
As part of the holiday spirit, you can use the following code at checkout on any redbox machine, once per credit card, and the rental will be on me:<br/><br/>
<span style="font-size:16px; color:#F00">DVDONME</span><br/><br/>
Happy Holidays from the Portal Web Programmer! Check Back Tomorrow For Another Gift!
</center>
<br/>
<?php } ?>
<?php if(date('j') == 2){ ?>
<h1>Happy Holidays! - Chips and Queso on Me</h1>
<br/>
<center>
As part of the holiday spirit, you can use the following coupon for chips and queso on me:<br/><br/>
<img src="images/chilies.png" style="float:none"/>
<br/><br/>
Happy Holidays from the Portal Web Programmer! Check Back Tomorrow For Another Gift!
</center>
<br/>
<?php } ?>
<?php if(date('j') == 3 or date('j') == 6){ ?>
<h1>Happy Holidays! - Regular Roast Beef on Me</h1>
<br/>
<center>
As part of the holiday spirit, you can use the following coupon for an Arby's Regular Roast Beef on me:<br/><br/>
<img src="images/arbys.png" style="float:none"/>
<br/><br/>
Happy Holidays from the Portal Web Programmer!
</center>
<br/>
<?php } ?>